import Router from 'koa-router'
import { Setting } from '../../service'
const router = new Router();

router.get('/index', async(ctx)=>{
    return await Setting.get('index')
})
router.get('/about', async(ctx)=>{
    return await Setting.get('about')
})
router.get('/help', async(ctx)=>{
    return await Setting.get('help')
})
router.get('/license', async(ctx)=>{
    return await Setting.get('license')
})
router.post('/setIndex', async(ctx)=>{
    if(ctx.request.body && ctx.request.body.value){
        return await Setting.save('index', ctx.request.body.value)
    }else{
        ctx.throw(401, 'bad request');
    }
})
router.post('/setAbout', async(ctx)=>{
    if(ctx.request.body && ctx.request.body.value){
        return await Setting.save('about', ctx.request.body.value)
    }else{
        ctx.throw(401, 'bad request');
    }
})
router.post('/setHelp', async(ctx)=>{
    if(ctx.request.body && ctx.request.body.value){
        return await Setting.save('help', ctx.request.body.value)
    }else{
        ctx.throw(401, 'bad request');
    }
})
router.post('/setLicense', async(ctx)=>{
    if(ctx.request.body && ctx.request.body.value){
        return await Setting.save('license', ctx.request.body.value)
    }else{
        ctx.throw(401, 'bad request');
    }
})

export default router
